% Process the eej strength derived from satellite data
% and compare it with ground deribed eej indices
%latest date 30 OCT 2005

data = load('c:\manoj\projects\eej\eej_par_all.txt');
data1 = load('c:\manoj\projects\eej\eejdata.txt');

x1data = [-60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60];
%x1data = [-60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60]
obs_index = 7; %ETT-HYB = 7,ETT-ABG = 8;TIR-HYB = 9;TIR-ABG = 10
eej_index = 10; %Pear Current Density = 9; av cur distan 10;
incrlat = 5; %NOTE change the main loop & x1data if any changes are made here
ndd = zeros([1,100]);
nloop = 1
lto = [];
ltc = [];
xdata = [];
ceff = [];
nbin = 1;
IE = ones([50,50])*NaN;
IO = IE;
for ki = 15.3:incrlat:135.3 % for incr 5
%for ki = 12.8:incrlat:132.8 % for incr 10
L = data(:,2) >= ki & data(:,2) <= ki+incrlat & data(:,1) <= max(data1(:,1));
IndiaE = data(L,:);
ndata = 1;
ind1 = [];
ind2 = [];
ltt1 = [];
ltt2 = [];
nnodata=1;
for i = 1:length(IndiaE(:,1)),
    ind = findnearest(IndiaE(i,1),data1(:,1));
    [lt1,dummy1] = champ_lt(IndiaE(i,1),IndiaE(i,2)); % Get the local time from UT (fday) and longitude of champ pass
    [dummy2,lt2] = champ_lt(data1(ind,1),IndiaE(i,2)); % Get the corresponding LT of Observatory hourly data 
       
        if lt1 > 10 & lt1 < 13 & lt2 > 10 & lt2 < 12 & abs(data1(ind,obs_index)) < 200, %Take only the LT's between x and y and 
            ind1(ndata) = ind;
            ndata = ndata+1;
        else,
            ind2(nnodata) = i;
            nnodata = nnodata + 1;
        end;
end;

if length(ind2) > 0,
    IndiaE(ind2,:) = [];
end;

if length(ind1) > 1,
    obsE = data1(ind1,:);
    IE(nbin,1:length(ind1)) = IndiaE(:,eej_index)';
    IO(nbin,1:length(ind1)) = obsE(:,obs_index)';
    xdata(nloop) = ki+incrlat/2;
    ndd(nloop) = ndata;
    nloop = nloop +1;
else,
    x1data(nbin) = NaN;
     
end;
nbin = nbin + 1;
clear ind f_ch f_ob ind1 ind2 ndata nnodata IndiaE obsE ltt1 ltt2 ltt3 ltt4 obst chpt;
end;

IE(nbin:end,:) = [];
IO(nbin:end,:) = [];
L = isnan(x1data);
x1data(L) = [];
IE(L,:) = [];
IO(L,:) = [];